package cn.tedu.charging.user.controller;

import cn.tedu.charging.common.pojo.param.ChargeParam;
import cn.tedu.charging.common.pojo.param.VehicleBindParam;
import cn.tedu.charging.common.pojo.vo.BalanceVO;
import cn.tedu.charging.common.pojo.vo.VehicleVO;
import cn.tedu.charging.common.protocol.JsonResult;
import cn.tedu.charging.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/user/wx/login")
    public JsonResult<Integer> wxLogin(String code, String nickName){
        log.info("微信登录，code={},nickName={}",code,nickName);
        Integer userId =userService.wxLogin(code,nickName);
        return JsonResult.ok(userId);
    }
    @GetMapping("/user/vehicle/binded/{userId}")
    public JsonResult<VehicleVO> bindeVehicle(@PathVariable Integer userId){
        VehicleVO vehicleVO = userService.bindeVehicle(userId);
        return  JsonResult.ok(vehicleVO);
    }
    @PostMapping("/user/vehicle/bind")
    public JsonResult<Integer> bindVehicle(@RequestBody VehicleBindParam param){
       Integer userId = userService.bindVehicle(param);
        return JsonResult.ok(userId);
    }
    @GetMapping("/user/vehicle/unbind")
    public JsonResult unbindVehicle(Integer userId){
        Integer result = userService.unbindVehicle(userId);
        return JsonResult.ok(null);
    }
    @GetMapping("/user/balance/{userId}")
    public JsonResult<BalanceVO> getBalance(@PathVariable("userId") Integer userId){
        BalanceVO balanceVO = userService.getBalance(userId);
        return JsonResult.ok(balanceVO);
    }
    @PostMapping("/user/charge")
    public JsonResult charge(@RequestBody ChargeParam param){
        userService.charge(param);
        return JsonResult.ok(null);
    }
}












